import { defineStore } from 'pinia'
import type { Customer } from '@/types/customer'
import request from '@/utils/request'

export const useCustomerStore = defineStore('customer', {
  state: () => ({
    customers: [] as Customer[],
    loading: false,
    error: null as string | null
  }),

  actions: {
    async getCustomers(params: { page: number; size: number }) {
      try {
        const response = await request.get('/customers', { params })
        return response.data
      } catch (error) {
        console.error('获取客户列表失败:', error)
        throw error
      }
    },

    async deleteCustomer(id: number) {
      try {
        await request.delete(`/customers/${id}`)
      } catch (error) {
        console.error('删除客户失败:', error)
        throw error
      }
    }
  }
}) 